interface countTax {
    //【必填】是否含税
    whetherTax: number;
    //税率
    taxRate?: number | null | any;
    //【必填】乘整倍数
    capacity: number;
    //【必填】单价
    purchasePrice: number;
    //【必填】数量
    purchaseQuantity: number;
}
//未税金额
let amountNotTaxed: any = 0
// 税额
let tax: any = 0
//价税合计
let totalValueTax: any = 0

export function useCountTax() {
    //价税合计
    function sumTotalValueTax(options: countTax) {
        if (options.whetherTax == 1) {
            console.log(options.purchaseQuantity,options.capacity,(options.purchasePrice * options.capacity),(options.capacity * options.capacity))
            return ((options.purchaseQuantity * options.capacity) * (options.purchaseQuantity * options.capacity) / (options.capacity * options.capacity)).toFixed(2)
            
        } else {
            console.log(123)
            //未税金额 = 数量* 销售单价
            amountNotTaxed = ((options.purchaseQuantity * options.capacity * (options.purchasePrice * options.capacity)) / (options.capacity * options.capacity)).toFixed(2);
            // 税额 = 未税金额 /(1 + 税率) * 税率
            tax = ((amountNotTaxed / (1 + options.taxRate)) * options.taxRate).toFixed(2);
            //价税合计 = 未税金额+ 税额
            return Number(amountNotTaxed) + Number(tax)
        }
    }
    // 税额
    function sumTax(options: countTax) {
        if (options.whetherTax == 1) {
            // 税额 = 价税合计 /(1 + 税率) * 税率
            totalValueTax = ((options.purchaseQuantity * options.capacity) * (options.purchaseQuantity * options.capacity) / (options.capacity * options.capacity)).toFixed(2)
            return ((totalValueTax / (1 + options.taxRate)) * options.taxRate).toFixed(2);
        } else {
            //未税金额 = 数量* 销售单价
            amountNotTaxed = ((options.purchaseQuantity * options.capacity * (options.purchasePrice * options.capacity)) / (options.capacity * options.capacity)).toFixed(2);
            // 税额 = 未税金额 /(1 + 税率) * 税率
            return ((amountNotTaxed / (1 + options.taxRate)) * options.taxRate).toFixed(2);
        }
    }
    // 未税金额
    function sumAmountNotTaxed(options: countTax) {
        if (options.whetherTax == 1) {
           
            totalValueTax = ((options.purchaseQuantity * options.capacity) * (options.purchaseQuantity * options.capacity) / (options.capacity * options.capacity)).toFixed(2)
            // 税额 = 价税合计 /(1 + 税率) * 税率
            tax = ((totalValueTax / (1 + options.taxRate)) * options.taxRate).toFixed(2);
            return (totalValueTax - tax).toFixed(2);
        } else {
            //未税金额 = 数量* 销售单价
            return ((options.purchaseQuantity * options.capacity * (options.purchasePrice * options.capacity)) / (options.capacity * options.capacity)).toFixed(2);
        }
    }
    return {
        sumTotalValueTax,
        sumTax,
        sumAmountNotTaxed
    }
}